
#include "Timer.hpp"
#include <iostream>
#include <string>
#include <iomanip>
#define WIDTH 20
#define Print std::cout << std::setw(WIDTH)

using namespace std::chrono;

Timer::Timer() : started_(false), paused_(false) {}
Timer::Timer(std::string msg) : msg(msg) { Start(); }

void Timer::Start()
{
    started_ = true;
    paused_ = false;
    start_time_ = high_resolution_clock::now();
}

void Timer::Restart()
{
    started_ = false;
    Start();
}

void Timer::Pause()
{
    paused_ = true;
    pause_time_ = high_resolution_clock::now();
}

void Timer::Resume()
{
    paused_ = false;
    start_time_ += high_resolution_clock::now() - pause_time_;
}

void Timer::Reset()
{
    started_ = false;
    paused_ = false;
}

double Timer::ElapsedMicroSeconds() const // 微秒
{
    if (!started_)
    {
        return 0.0;
    }
    if (paused_)
    {
        return duration_cast<microseconds>(pause_time_ - start_time_).count();
    }
    else
    {
        return duration_cast<microseconds>(high_resolution_clock::now() -
                                           start_time_)
            .count();
    }
}

double Timer::ElapsedSeconds() const { return ElapsedMicroSeconds() / 1e6; }

double Timer::ElapsedMinutes() const { return ElapsedSeconds() / 60; }

double Timer::ElapsedHours() const { return ElapsedMinutes() / 60; }

void Timer::PrintSeconds(const std::string &str) const
{
    std::cout.setf(std::ios::left); // 设置对齐方式为left
    Print << str << ElapsedSeconds() << " s"
          << "\n";
}

void Timer::PrintMinutes() const
{
    printf("Elapsed time: %.3f [minutes]\n", ElapsedMinutes());
}

void Timer::PrintHours() const
{
    printf("Elapsed time: %.3f [hours]\n", ElapsedHours());
}
using namespace std;
#include <opencv2/opencv.hpp>
#include <vector>
#include <fstream>
#include <map>

int main()
{
    struct NowDate
    {
        char tmp0[16];       // 年月日
        char tmp1[16];       // 时分秒
        char filename[128];  // 年月日时分秒
        char rgbname[256];   // 年月日时分秒
        char depthname[256]; // 年月日时分秒

        struct timeval tv;
        string fn;
        NowDate()
        {
            update();
            fn = string(filename);
        }
        time_t timep;
        void update()
        {
            time(&timep);
            gettimeofday(&tv, NULL);
            // strftime(tmp0, sizeof(tmp0), "%Y_%m_%d", localtime(&timep));
            // strftime(tmp1, sizeof(tmp1), "%H_%M_%S", localtime(&timep));
            strftime(filename, sizeof(filename), "%Y_%m_%d_%H_%M_%S", localtime(&timep));
            sprintf(rgbname, "img/%s_%ld_dep.png", filename, tv.tv_usec);
            sprintf(depthname, "img/%s_%ld_rgb.png", filename, tv.tv_usec);

            printf("%s %s\n", filename, depthname, rgbname);
        }

        void readfiles(vector<string> &rgbs, string path)
        {
            fstream fs(path + "/file.txt", std::ios::in);

            while (1)
            {
                string n, n2;
                fs >> n >> n2;
                if (!fs.good())
                    break;
                rgbs.push_back(n);
                rgbs.push_back(n2);
            }
            // rgbs.pop_back
        }
    };

    NowDate date;
    date.update();
    system(cv::format("mkdir -p %s/img", date.fn.c_str()).c_str());
    int c = 10;
    fstream fs(date.fn + "/file.txt", std::ios::out);
    while (c--)
    {
        date.update();
        fs << string(date.depthname) << " " << string(date.rgbname) << endl;
    }
    fs.close();
    vector<string> rgbs;
    date.readfiles(rgbs, date.fn);
    for (auto &t : rgbs)
    {
        cout << t << endl;
    }
    vector<string> fss;

    system("python3 a.py");
    fstream fs2("task.txt", std::ios::in);
    while (1)
    {
        string n;
        fs2 >> n;
        if (!fs2.good())
            break;
        fss.push_back(n);
    }

     for (auto &t : fss)
    {
        cout << t << endl;
    }

}